(SST) ShlWAPI.pas Version 1.08

Developer Reference
(SST)ShlWAPI PathIsRelative Function
Checks if a path string refers to a relative path or not.
Scope
Global (i.e. this function can be called/accessed from code in any unit that includes/uses (SST)ShlWAPI.pas).
Syntax
function PathIsRelative(pszPath : LPCSTR) : BOOL;
Parameters
pszPath [in] Pointer to a NULL terminated string that is the path to check. This string, including the terminating NULL character, should not exceed MAX_PATH (= 260 ANSI or Unicode characters, depending on which version is called) in length.
Return Values
The function returnd TRUE (= 1) if the specified path (pszPath) is syntactically a relative, Windows/DOS path. It returns FALSE (= 0) if the path is a fully qualified/absolute, Windows path.
Remarks
The function works faultlessly with Windows paths. However, if the path deviates from the Windows syntax for file system/nwetwork paths, it may return an unexpected result (see examples, below).
The function apparently does not verify the existence of the referenced resource(s). .
If called with a URL instead of a relative, Windows path (i.e. a path referring to a local or network file system object), the function may also return TRUE (see final example, below).
Example
PROCEDURE TForm4.TestShlWAPIPathIsRelative(Sender : TObject); VAR pathtotest : STRING; VAR apiretval : BOOL; VAR newinfoline : STRING; BEGIN pathtotest := ''; apiretval := FALSE; newinfoline := ''; //Calls that should return TRUE pathtotest := '..\System32\Kernel32.dll'; newinfoline := 'PathIsRelative called with ' + pathtotest; Memo1.Lines.Add(newinfoline); apiretval := PathIsRelative(PChar(pathtotest)); IF apiretval THEN newinfoline := 'TRUE' ELSE newinfoline := 'FALSE'; Memo1.Lines.Add(newinfoline); pathtotest := '\System32\drivers\en-US'; newinfoline := 'PathIsRelative called with ' + pathtotest; Memo1.Lines.Add(newinfoline); apiretval := PathIsRelative(PChar(pathtotest)); IF apiretval THEN newinfoline := 'TRUE' ELSE newinfoline := 'FALSE'; Memo1.Lines.Add(newinfoline); pathtotest := '.\Program Files\Windows NT\Accessories\en-US'; newinfoline := 'PathIsRelative called with ' + pathtotest; Memo1.Lines.Add(newinfoline); apiretval := PathIsRelative(PChar(pathtotest)); IF apiretval THEN newinfoline := 'TRUE' ELSE newinfoline := 'FALSE'; Memo1.Lines.Add(newinfoline); pathtotest := 'Sample Folder\SubFolder\FileNameNoExt'; newinfoline := 'PathIsRelative called with ' + pathtotest; Memo1.Lines.Add(newinfoline); apiretval := PathIsRelative(PChar(pathtotest)); IF apiretval THEN newinfoline := 'TRUE' ELSE newinfoline := 'FALSE'; Memo1.Lines.Add(newinfoline); pathtotest := 'Sample2Folder\SubFolder2\FileName.Ext'; newinfoline := 'PathIsRelative called with ' + pathtotest; Memo1.Lines.Add(newinfoline); apiretval := PathIsRelative(PChar(pathtotest)); IF apiretval THEN newinfoline := 'TRUE' ELSE newinfoline := 'FALSE'; Memo1.Lines.Add(newinfoline); pathtotest := '../UnixFolder/SubFolder3/UnixFile.ext'; newinfoline := 'PathIsRelative called with ' + pathtotest; Memo1.Lines.Add(newinfoline); apiretval := PathIsRelative(PChar(pathtotest)); IF apiretval THEN newinfoline := 'TRUE' ELSE newinfoline := 'FALSE'; Memo1.Lines.Add(newinfoline); pathtotest := '/UnixFolder2/SubFolder4/NoName'; newinfoline := 'PathIsRelative called with ' + pathtotest; Memo1.Lines.Add(newinfoline); apiretval := PathIsRelative(PChar(pathtotest)); IF apiretval THEN newinfoline := 'TRUE' ELSE newinfoline := 'FALSE'; Memo1.Lines.Add(newinfoline); pathtotest := './UnixFolder2/SubFolder4/NoName'; newinfoline := 'PathIsRelative called with ' + pathtotest; Memo1.Lines.Add(newinfoline); apiretval := PathIsRelative(PChar(pathtotest)); IF apiretval THEN newinfoline := 'TRUE' ELSE newinfoline := 'FALSE'; Memo1.Lines.Add(newinfoline); //Calls that should return FALSE pathtotest := 'C:\Windows\System32\Kernel32.dll'; newinfoline := 'PathIsRelative called with ' + pathtotest; Memo1.Lines.Add(newinfoline); apiretval := PathIsRelative(PChar(pathtotest)); IF apiretval THEN newinfoline := 'TRUE' ELSE newinfoline := 'FALSE'; Memo1.Lines.Add(newinfoline); pathtotest := '\\SAMPLESRVER\Share\RemoteFolder\RemoteFile.ext'; newinfoline := 'PathIsRelative called with ' + pathtotest; Memo1.Lines.Add(newinfoline); apiretval := PathIsRelative(PChar(pathtotest)); IF apiretval THEN newinfoline := 'TRUE' ELSE newinfoline := 'FALSE'; Memo1.Lines.Add(newinfoline); pathtotest := 'http://sampledomain.smp/samplefolder/page.htm'; newinfoline := 'PathIsRelative called with ' + pathtotest; Memo1.Lines.Add(newinfoline); apiretval := PathIsRelative(PChar(pathtotest)); IF apiretval THEN newinfoline := 'TRUE' ELSE newinfoline := 'FALSE'; Memo1.Lines.Add(newinfoline); END;
Under Windows Vista with Service Pack 1 (SP 1) and IE 8 the above code producesd the following output:
PathIsRelative called with ..\System32\Kernel32.dll TRUE PathIsRelative called with \System32\drivers\en-US FALSE PathIsRelative called with .\Program Files\Windows NT\Accessories\en-US TRUE PathIsRelative called with Sample Folder\SubFolder\FileNameNoExt TRUE PathIsRelative called with Sample2Folder\SubFolder2\FileName.Ext TRUE PathIsRelative called with ../UnixFolder/SubFolder3/UnixFile.ext TRUE PathIsRelative called with /UnixFolder2/SubFolder4/NoName TRUE PathIsRelative called with ./UnixFolder2/SubFolder4/NoName TRUE PathIsRelative called with C:\Windows\System32\Kernel32.dll FALSE PathIsRelative called with \\SAMPLESRVER\Share\RemoteFolder\RemoteFile.ext FALSE PathIsRelative called with http://sampledomain.smp/samplefolder/page.htm TRUE
Requirements
Unit: Declared and imported in (SST)ShlWAPI.pas
Library: (SST)ShlWAPI.dcu/(SST)ShlWAPI.obj
Unicode: Implemented as ANSI (PathIsRelative and PathIsRelativeA) and Unicode (PathIsRelativeW) functions.
Min. ShlWAPI.dll version according to MS SDK doc.: 4.71
Min. ShlWAPI.dll version based on SST research: 4.71
Min. OS version(s) according to Microsoft SDK doc.: Windows 2000, Windows NT 4.0 with Internet Explorer 4.0, Windows 98, Windows 95 with Internet Explorer 4.0
Min. OS version(s) according to SST research.: Windows NT 4.0 with IE 4.0, Windows 95 with IE 4.0, Windows 98 and later
See Also
PathIsRoot, PathIsLFNFileSpec, PathIsUNC.
 
Windows APIs: GetLastError, SetLastError PathIsRoot, PathIsFileSpec, PathIsLFNFileSpec, PathIsPrefix, PathIsUNC, PathMatchSpec, PathMatchSpecEx, PathRemoveFileSpec


Document/Contents version 1.00
Page/URI last updated on 07.12.2023
 
Copyright © Stoelzel Software Technologie (SST) 2010 - 2015
Suggestions and comments mail to:
webmaster@stoelzelsoftwaretech.com